/**
 * @file ProtocolDriver.h
 * @author SoBigDog (623644973lubin@163.com)
 * @brief 
 * @version 0.1
 * @date 2020-11-16
 * 
 * @copyright Copyright (c) 2020
 * 
 */
#ifndef _PROTOCOL_DRIVER_H_
#define _PROTOCOL_DRIVER_H_

#include <stdint.h>
#include "stm32f1xx_hal.h"
#include <stdbool.h>
//#include "MotorDriver.h"

extern CAN_HandleTypeDef hcan;

enum motorDriverCmdType{
	DRV_CMD_NULL,
	DRV_CMD_ACTURAL_POS,
	DRV_CMD_ACTURAL_SPEED,
	DRV_CMD_TARGET_SPEED,
	DRV_CMD_DRI_EMC,
	DRV_CMD_DRI_ERR,
	DRV_CMD_DRI_ERRCODE,
	DRV_CMD_DRI_STATE,
	DRV_CMD_INIT_CMD,
	DRV_CMD_VERSION,
	DRV_CMD_ENABLE,
	DRV_CMD_DISABLE,
	DRV_CMD_TARGET_POS_OK,
	DRV_CMD_TARGET_POS,
	DRV_CMD_TARGET_POS_FINISHED,
	DRV_CMD_IO_STAT,
	DRV_CMD_CLEAN_ENCODE,
	DRV_CMD_GO_ZERO,
	DRV_CMD_CHECK_ZERO,
	DRV_CMD_ZERO_FINISHED,
	DRV_CMD_FORK_VEL,
	DRV_CMD_AUTO_MODE,
	DRV_CMD_FORK_FORWARD_STATE,
	DRV_CMD_OPERATIONAL,
	DRV_CMD_MOTOR_LIMIT,
	DRV_CMD_MOTOR_CURRENT,
	DRV_CMD_MOTOR_TEMPERATURE,
	DRV_CMD_UNDEFINED,
};

enum DriverProtocolEnum {
	Protocol_RL = 1,
	Protocol_CanOpen,
	Protocol_Castdservo,
	Protocol_Keya_1to1,
	Protocol_CanOpenPosition,
	Protocol_HLS,
	Protocol_DeltaCanopen,
	Protocol_KincoCanopen,
	Protocol_HlsCanopen,
	Protocol_Curtis,
	Protocol_MotecCanopen,
	Protocol_JingZhiCanopen,
	Protocol_MingZhiCanopen,
	Protocol_Keya_1to2,
	Protocol_NanotecCanopen
};

struct driver_protocol {
	bool 	(*encode)(enum motorDriverCmdType, int32_t);
	int 	(*decode)(enum motorDriverCmdType **, int32_t **);
};

//class CDriverProtocol
//{
//public:
//	CDriverProtocol() {
//		_motor_power_on_wait_time = 0;
//		reset();
//	}
//
//	inline void reset (){
//		_motorId = 0;
//	};
//
//	uint32_t getMotorId()
//	{
//		return _motorId;
//	}
//	
//	virtual void setMotorId(uint32_t id) {
//		_motorId = id;
//	}
//
//	void setReductionRatio(float rr)
//	{
//		_reductionRatio = rr;
//	}
//	
//	float getReductionRatio(void)
//	{
//		return _reductionRatio;
//	}
//
//	virtual int32_t getWaitTime_ms() {return _motor_power_on_wait_time;}
//	virtual void setMaxRpm(uint32_t maxRpm) {_max_rpm = maxRpm;}
//	virtual void setMotorType(uint32_t type) {_motorType = type;}
//	virtual bool encode(motorDriverCmdType ct, int32_t val) = 0;
//	//virtual int decode(motorDriverCmdType (&ct)[10], int32_t (&val)[10], const CanRxMsg&) = 0;
//	
//
//	virtual void setSteerRange(uint32_t range){return;}
//	virtual double getCurrentFactor(){return 1.0f;}
//	virtual double getTemperatureFactor(){return 1.0f;}
//protected:
//	uint32_t _motorId;
//	uint32_t _encoderLine;
//	float _reductionRatio;
//	uint32_t _motorType;
//	uint32_t _max_rpm;
//	int32_t _motor_power_on_wait_time;
//};
												
#endif
